package io.itit.ecp.admin.provide.selected;

import io.itit.ecp.admin.server.entity.SceneEdificeEntity;
import io.itit.ecp.admin.server.service.ISceneEdificeService;
import io.itit.grass.common.provide.action.resp.SelectedResp;
import io.itit.grass.common.server.selected.ISelected;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 能源类型选择器
 */
@Component
public class SceneEdificeSelected implements ISelected<SelectedResp> {

    public static final String CODE = "SceneEdificeSelected";

    @Resource
    private ISceneEdificeService sceneEdificeService;

    @Override
    public String code() {
        return CODE;
    }

    @Override
    public List<SelectedResp> get(String param) {
        return sceneEdificeService.lambdaQuery()
                .eq(StringUtils.isNotEmpty(param), SceneEdificeEntity::getSceneProjectId, param)
                .orderByAsc(SceneEdificeEntity::getEdificeName)
                .list()
                .stream()
                .map(t -> SelectedResp.builder().label(t.getEdificeName()).value(t.getId()).build())
                .collect(Collectors.toList());
    }
}
